package com.cmy.b_claculator.ui.details

import androidx.lifecycle.MutableLiveData
import com.cmy.b_claculator.db.ClaculatorDatabase
import com.cmy.b_claculator.db.dao.WorkDateDao
import com.cmy.b_claculator.model.WorkModel
import me.hgj.jetpackmvvm.base.appContext
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.callback.databind.StringObservableField

class WorkDetailsViewModel :BaseViewModel() {


    /**数据库对象*/
    private  var dao : WorkDateDao =  ClaculatorDatabase.getInstance(appContext).workDao

    val money : StringObservableField = StringObservableField()
    val time:StringObservableField = StringObservableField()

     var id:Long  = 0

     var listDataState:MutableLiveData<MutableList<WorkModel>> =  MutableLiveData<MutableList<WorkModel>>()



    fun initData() {
        val entity = dao.queryWorkDateById(id)
        entity?.let {
            money.set("总金额：￥${it.money}")
            time.set(it.time)
        }
        listDataState.value = dao.queryWork(id)
    }

}